package com.igeek.config.ch03.properties;


import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.Scope;

import javax.sql.DataSource;
import java.beans.PropertyVetoException;

/**
 *
 */
@PropertySource("db.properties")
public class DataSourceConfig {
    @Bean
    @Scope("prototype")
    public DataSource dataSource(
            @Value("${db.user}") String username,
            @Value("${db.password}") String password,
            @Value("${db.url}") String jdbcUrl,
            @Value("${db.driverClass}")String driverClass

    ) throws PropertyVetoException {
        ComboPooledDataSource dataSource = new ComboPooledDataSource();
        dataSource.setUser(username);
        dataSource.setPassword(password);
        dataSource.setJdbcUrl(jdbcUrl);
        dataSource.setDriverClass(driverClass);
        return dataSource;

    }
}
